package com.threeti.mecool.core.infrastructure.persistence.plan;

import com.threeti.mecool.core.domain.model.plan.PlanJobResult;
import com.threeti.mecool.core.domain.model.plan.UserStepResult;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface UserStepResultRepository extends JpaRepository<UserStepResult, Long>, JpaSpecificationExecutor<UserStepResult> {
    UserStepResult findByUserLoginNameAndStep_IdAndPlanJobResult_PlanJob_Id(String userLoginName, Long stepId, Long planJobId);

    @Query("select usr from UserStepResult usr,Project proj where proj.category.id = ?1 and usr.projectCode = proj.code")
    Page<UserStepResult> findByProjectCategoryId(Long projectCategoryId, Pageable pageable);

    List<UserStepResult> findByPlanJobResult(PlanJobResult planJobResult, Sort sort);
}
